package com.lipl.base.javaee.spring;

import org.springframework.util.StopWatch;

/**
 * @Auther: 15541
 * @Date: 2021/5/18 13:49
 * @Description:
 */
public class StopWatchTest {
    public static void main(String[] args) throws InterruptedException {
        test0();
        test1();
    }

    public static void test0 () throws InterruptedException {
        long start = System.currentTimeMillis();
        // do something
        Thread.sleep(100);
        long end = System.currentTimeMillis();
        long start2 = System.currentTimeMillis();
        // do something
        Thread.sleep(200);
        long end2 = System.currentTimeMillis();
        System.out.println("某某1执行耗时:" + (end - start));
        System.out.println("某某2执行耗时:" + (end2 - start2));
    }

    public static void test1() throws InterruptedException {
        StopWatch sw = new StopWatch("test");
        sw.start("task1");
        // do something
        Thread.sleep(10000);
        sw.stop();
        sw.start("task2");
        // do something
        Thread.sleep(200000);
        sw.stop();
        System.out.println("sw.prettyPrint()~~~~~~~~~~~~~~~~~");
        System.out.println(sw.prettyPrint());
    }

}

